//
//  PicHeader.m
//  HYHoney
//
//  Created by dllo on 16/1/29.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "PicHeader.h"
#import "ModelOfPic.h"
#import "DKNightVersion.h"

@implementation PicHeader

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithReuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        [self createVC];
    }
    return self;
}


- (void)dealloc{

    [_descTop release];
    [_titleN release];
    [super dealloc];
}


- (void)createVC{
    
    self.titleN = [[UILabel alloc] init];
    self.titleN.textAlignment = NSTextAlignmentCenter;
    self.titleN.font = [UIFont boldSystemFontOfSize:26];
    [self.contentView addSubview:self.titleN];

    self.descTop = [[UILabel alloc] init];
    self.descTop.numberOfLines = 0;
    self.descTop.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:self.descTop];
}


- (void)layoutSubviews{
    
    [super layoutSubviews];
    
    self.titleN.frame = CGRectMake(20, 0, self.contentView.frame.size.width - 40, 50);
    self.titleN.textAlignment = NSTextAlignmentCenter;
    self.titleN.font = [UIFont boldSystemFontOfSize:17];
    
    self.descTop.frame = CGRectMake(20, 50 + 10, self.frame.size.width - 40, [[self class] heightForLabel:self.descTop.text]);
}


+ (CGFloat)heightForLabel:(NSString *)text{
    
    CGRect rect = [text boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width - 40, 0) options: NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]} context:nil];
    
    return rect.size.height;
}


+ (CGFloat)heightForCell:(ModelOfPic *)model{
    
    CGFloat height = [PicHeader heightForLabel:model.desc];
    
    return height + 50 + 10;
}


-(void)passModel:(ModelOfPic *)model{
    
    self.descTop.text = model.desc;
    self.descTop.dk_textColorPicker = DKColorWithRGB(0x000000, 0xefffff);
    
    self.titleN.text = model.name;
    self.titleN.dk_textColorPicker = DKColorWithRGB(0x000000, 0xefffff);
    
    self.contentView.dk_backgroundColorPicker = DKColorWithRGB(0xFFFAFA, 0x324476);
}

@end
